package com.etc.service.impl;

import com.etc.dao.PatientMapper;
import com.etc.dao.PayMapper;
import com.etc.entity.Patient;
import com.etc.entity.Pay;
import com.etc.service.PayService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class PayServiceImpl implements PayService {

    @Autowired
    private PayMapper payMapper;

    @Autowired
    private PatientMapper patientMapper;

    @Override
    public List<Pay> getPayPatientDetailListSelective(Pay pay) {
        return null;
    }

    @Override
    public List<Pay> getPayListByPatientId(String patientId) {


        List<Pay> payList = payMapper.findListByPatientId(patientId);
        return payList;
    }

    @Override
    public boolean updatePayContent(String patientName, String content) {
        Patient patient = new Patient();
        patient.setPatientName(patientName);
        List<Patient> patients = patientMapper.findSelective(patient);
        String patientId = patients.get(0).getPatientId();
        Pay pay = new Pay();
        pay.setOrderId(patientId);
        pay.setContent(content);
        int i = payMapper.updatePayDetail(pay);

        return i > 0;
    }

    @Override
    public List<Pay> getPayOrderDoctorPatientList() {
        List<Pay> payOrderDoctorPatientList = payMapper.findPayOrderDoctorPatientList();
        return payOrderDoctorPatientList;
    }

    @Override
    public PageInfo<Pay> getPayOrderDoctorPatientListByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Pay> payOrderDoctorPatientList = payMapper.findPayOrderDoctorPatientList();
        PageInfo<Pay> pageInfo = new PageInfo<>(payOrderDoctorPatientList);
        return pageInfo;
    }
}
